package com.ysxsoft.wdg.view;

import android.content.Context;
import android.graphics.Canvas;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.ysxsoft.wdg.R;


public class EStarView extends LinearLayout {
	private int maxStar = 5;
	private boolean canDrag = false;

	public EStarView(Context context) {
		this(context, null);
	}

	public EStarView(Context context, @Nullable AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public EStarView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init(context, attrs);
	}

	private void init(Context context, AttributeSet attrs) {
		setWillNotDraw(false);
		setOrientation(HORIZONTAL);
		for (int i = 0; i < maxStar; i++) {
			ImageView imageView = new ImageView(context);
			imageView.setSelected(false);
			imageView.setImageDrawable(getResources().getDrawable(R.drawable.bg_start));
			addView(imageView);
			imageView.setTag(i);
		}
	}

	public void setStar(int p) {
		for (int i = 0; i < p; i++) {
			ImageView imageView = (ImageView) getChildAt(i);
			if (i <= p) {
				imageView.setSelected(true);
			} else {
				imageView.setSelected(false);
			}
		}
		requestLayout();
	}


	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
	}


	@Override
	public boolean onTouchEvent(MotionEvent event) {
		switch (event.getAction()) {
			case MotionEvent.ACTION_DOWN:
				break;
			case MotionEvent.ACTION_MOVE:
				if(canDrag){
				}
				break;
			case MotionEvent.ACTION_UP:
				break;
		}
		return true;
	}
}
